package com.tianqu.tms.www.transfer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.transfer.actionform.TransferRgActionForm;
import com.tianqu.tms.www.transfer.controller.PLicenseInputResultController;
import com.tianqu.tms.www.transfer.viewhelper.TransferRgInputViewHelper;

public class PLicenseInputResultAction extends TmsAction {

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		isToken(mapping, request);
        TransferRgInputViewHelper view = (TransferRgInputViewHelper) uc
        .getAttribute(TmsConstants.VIEWHELP);
        view.setBusinessType(((TransferRgActionForm)form).getBusinessType());
        request.setAttribute(TmsConstants.VIEWHELP, view);

        TmsUserProfile profile = uc.getUserProfile();
//        Codes code = Codes.getInstance();
        TransferAcceptedInfo accept = new TransferAcceptedInfo();
//        uc.setAttribute(TmsConstants.VIEWHELP, view);
        accept = accept.getAcceptInfoOnlyBySerial(view.getSerial(),"");
        if (accept != null) {
            /*
             * 如果操作人类型是操作人员，即“当前操作人对应tms_user表的userType为：1，操作人员”根据车辆流水号（serial），搜索“过户业务基本信息表（tms_transfer_accepted_info）”
             * 中“牌证表打印缴费状态（conformityMark）”。如果“牌证表打印缴费状态（conformityMark）”为“2，未缴费”，则页提示“当前车辆未缴纳牌证费用，请缴费后进行查询。
             */
            if (profile.getUserType() == 1 && accept.getConformityMark() == 2) {
                setErrorsToRequest(request, TmsConstants.U12003 ,null);
//              return mapping.findForward(TmsConstants.SUCCESS);
                return mapping.getInputForward();
            }
        }
        
        
		PLicenseInputResultController controller = new PLicenseInputResultController();
		controller.execute(uc);
		uc.removeAttribute(TmsConstants.VIEWHELP);
		view.setPrintBsflag("1");
		request.setAttribute(TmsConstants.VIEWHELP, view);
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
